import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ItemData } from "../../resource/info/ItemData";
import { ItemMenuRegister } from "../common/menu/ItemMenuRegister";
import { ItemMenuConst } from "../common/menu/ItemMenuConst";
import { BaseItem } from "../common/BaseItem";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
//class DrugItemCellRenderer
    
    export  class DrugItemCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._itemData = arg1 as ItemData;
            this._baseItem.itemData = this._itemData;
            if (this._itemData && this._itemData.itemAmount > 1) 
            {
                ItemMenuRegister.register(this._baseItem, this._itemData, ItemMenuConst.DrugBag);
            }
            else 
            {
                ItemMenuRegister.unRegister(this._baseItem);
            }
            return;
        }

        /* internal  */init(): void
        {
            this._baseItem = new BaseItem();
            this._baseItem.isShowLock = true;
            this._baseItem.isDragAble = false;
            this._baseItem.width = 32;
            this._baseItem.height = 32;
            this._baseItem.move(2, 2);
            this.addChild(this._baseItem);
            this._baseItem.mouseEnabled = true;
            this._baseItem.mouseChildren = false;
            this._baseItem.doubleClickEnabled = true;
            this._baseItem.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDoubleClickHandler);
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this._itemData) 
            {
                this._baseItem.filters = [FilterConst.itemChooseFilter];
            }
            else 
            {
                this._baseItem.filters = [];
            }
            return;
        }

        /* internal  */onDoubleClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._itemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, this._itemData));
            }
            return;
        }

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_itemData: ItemData;
    }
